﻿<?xml version="1.0" encoding="utf-8"?><Articles><Article><ArticlesID>823</ArticlesID><Title>Đồng hồ kỹ thuật số với Javascript</Title><Body>&amp;lt;p&amp;gt;Tạo 1 file Javascript mới rồi copy đoạn code sau:&amp;lt;/p&amp;gt;
&amp;lt;pre class=&amp;quot;brush: jscript;&amp;quot; title=&amp;quot;code&amp;quot;&amp;gt;
var dn;
c1 = new Image(); c1.src = &amp;amp;quot;images/c1.gif&amp;amp;quot;;
c2 = new Image(); c2.src = &amp;amp;quot;images/c2.gif&amp;amp;quot;;
c3 = new Image(); c3.src = &amp;amp;quot;images/c3.gif&amp;amp;quot;;
c4 = new Image(); c4.src = &amp;amp;quot;images/c4.gif&amp;amp;quot;;
c5 = new Image(); c5.src = &amp;amp;quot;images/c5.gif&amp;amp;quot;;
c6 = new Image(); c6.src = &amp;amp;quot;images/c6.gif&amp;amp;quot;;
c7 = new Image(); c7.src = &amp;amp;quot;images/c7.gif&amp;amp;quot;;
c8 = new Image(); c8.src = &amp;amp;quot;images/c8.gif&amp;amp;quot;;
c9 = new Image(); c9.src = &amp;amp;quot;images/c9.gif&amp;amp;quot;;
c0 = new Image(); c0.src = &amp;amp;quot;images/c0.gif&amp;amp;quot;;
cb = new Image(); cb.src = &amp;amp;quot;images/cb.gif&amp;amp;quot;;
cam = new Image(); cam.src = &amp;amp;quot;images/cam.gif&amp;amp;quot;;
cpm = new Image(); cpm.src = &amp;amp;quot;images/cpm.gif&amp;amp;quot;;
function extract(h,m,s,type) {
if (!document.images) return;
if (h &amp;amp;lt;= 9) {
document.images.a.src = cb.src;
document.images.b.src = eval(&amp;amp;quot;c&amp;amp;quot;+h+&amp;amp;quot;.src&amp;amp;quot;);
}
else {
document.images.a.src = eval(&amp;amp;quot;c&amp;amp;quot;+Math.floor(h/10)+&amp;amp;quot;.src&amp;amp;quot;);
document.images.b.src = eval(&amp;amp;quot;c&amp;amp;quot;+(h%10)+&amp;amp;quot;.src&amp;amp;quot;);
}
if (m &amp;amp;lt;= 9) {
document.images.d.src = c0.src;
document.images.e.src = eval(&amp;amp;quot;c&amp;amp;quot;+m+&amp;amp;quot;.src&amp;amp;quot;);
}
else {
document.images.d.src = eval(&amp;amp;quot;c&amp;amp;quot;+Math.floor(m/10)+&amp;amp;quot;.src&amp;amp;quot;);
document.images.e.src = eval(&amp;amp;quot;c&amp;amp;quot;+(m%10)+&amp;amp;quot;.src&amp;amp;quot;);
}
if (s &amp;amp;lt;= 9) {
document.g.src = c0.src;
document.images.h.src = eval(&amp;amp;quot;c&amp;amp;quot;+s+&amp;amp;quot;.src&amp;amp;quot;);
}
else {
document.images.g.src = eval(&amp;amp;quot;c&amp;amp;quot;+Math.floor(s/10)+&amp;amp;quot;.src&amp;amp;quot;);
document.images.h.src = eval(&amp;amp;quot;c&amp;amp;quot;+(s%10)+&amp;amp;quot;.src&amp;amp;quot;);
}
if (dn == &amp;amp;quot;AM&amp;amp;quot;) document.j.src = cam.src;
else document.images.j.src = cpm.src;
}
function show3() {
if (!document.images)
return;
var Digital = new Date();
var hours = Digital.getHours();
var minutes = Digital.getMinutes();
var seconds = Digital.getSeconds();
dn = &amp;amp;quot;AM&amp;amp;quot;;
if ((hours &amp;amp;gt;= 12) &amp;amp;amp;&amp;amp;amp; (minutes &amp;amp;gt;= 1) || (hours &amp;amp;gt;= 13)) {
dn = &amp;amp;quot;PM&amp;amp;quot;;
hours = hours-12;
}
if (hours == 0)
hours = 12;
extract(hours, minutes, seconds, dn);
setTimeout(&amp;amp;quot;show3()&amp;amp;quot;, 1000);
}&amp;lt;/pre&amp;gt;
&amp;lt;p&amp;gt;trong sự kiện body onload gọi&amp;lt;/p&amp;gt;
&amp;lt;pre class=&amp;quot;brush: xhtml;&amp;quot; title=&amp;quot;code&amp;quot;&amp;gt;
&amp;amp;lt;BODY onLoad=&amp;amp;quot;show3();&amp;amp;quot; bgcolor=&amp;amp;quot;#000000&amp;amp;quot;&amp;amp;gt;&amp;lt;/pre&amp;gt;
&amp;lt;p&amp;gt;xuống dưới thẻ body copy tiếp đoạn code sau để hiện ảnh (số từ 0 --&amp;amp;gt;&amp;amp;nbsp;9)&amp;lt;/p&amp;gt;
&amp;lt;pre class=&amp;quot;brush: xhtml;&amp;quot; title=&amp;quot;code&amp;quot;&amp;gt;
&amp;amp;lt;img height=21 src=&amp;amp;quot;images/cb.gif&amp;amp;quot; width=16 name=a&amp;amp;gt;
&amp;amp;lt;img height=21 src=&amp;amp;quot;images/cb.gif&amp;amp;quot; width=16 name=b&amp;amp;gt;
&amp;amp;lt;img height=21 src=&amp;amp;quot;images/colon.gif&amp;amp;quot; width=9 name=c&amp;amp;gt;
&amp;amp;lt;img height=21 src=&amp;amp;quot;images/cb.gif&amp;amp;quot; width=16 name=d&amp;amp;gt;
&amp;amp;lt;img height=21 src=&amp;amp;quot;images/cb.gif&amp;amp;quot; width=16 name=e&amp;amp;gt;
&amp;amp;lt;img height=21 src=&amp;amp;quot;images/colon.gif&amp;amp;quot; width=9 name=f&amp;amp;gt;
&amp;amp;lt;img height=21 src=&amp;amp;quot;images/cb.gif&amp;amp;quot; width=16 name=g&amp;amp;gt;
&amp;amp;lt;img height=21 src=&amp;amp;quot;images/cb.gif&amp;amp;quot; width=16 name=h&amp;amp;gt;
&amp;amp;lt;img height=21 src=&amp;amp;quot;images/cam.gif&amp;amp;quot; width=16 name=j&amp;amp;gt;&amp;lt;/pre&amp;gt;
&amp;lt;p&amp;gt;Đoạn code kh&amp;amp;aacute;c:&amp;lt;/p&amp;gt;
&amp;lt;pre class=&amp;quot;brush: jscript;&amp;quot; title=&amp;quot;code&amp;quot;&amp;gt;
var gizmo;
 
function stopClock(){
  clearTimeout(gizmo);
}
 
function yourClock(){
  var nd = new Date();
  var h, m;
  var s;
  var time = &amp;amp;quot; &amp;amp;quot;;
  h = nd.getHours();
  m = nd.getMinutes();
  s = nd.getSeconds();
  if (h &amp;amp;lt;= 9) h = &amp;amp;quot;0&amp;amp;quot; + h;
  if (m &amp;amp;lt;= 9) m = &amp;amp;quot;0&amp;amp;quot; + m;
  if (s &amp;amp;lt;= 9) s = &amp;amp;quot;0&amp;amp;quot; + s;
  time += h + &amp;amp;quot;:&amp;amp;quot; + m + &amp;amp;quot;:&amp;amp;quot; + s;
  document.the_clock.the_tivalue = time;
  gizmo = setTimeout(&amp;amp;quot;yourClock()&amp;amp;quot;, 1000);
}&amp;lt;/pre&amp;gt;
&amp;lt;p&amp;gt;trong Body gọi&amp;lt;/p&amp;gt;
&amp;lt;pre class=&amp;quot;brush: xhtml;&amp;quot; title=&amp;quot;code&amp;quot;&amp;gt;
&amp;amp;lt;BODY onLoad=&amp;amp;quot;yourClock();&amp;amp;quot; bgcolor=&amp;amp;quot;#000000&amp;amp;quot;&amp;amp;gt;&amp;lt;/pre&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;http://demo.meotom.net/digital-clock/digital-clock.htm&amp;quot;&amp;gt;xem Demo&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;http://dev.meotom.net/Uploads/admin/2010/3/8/digital-clock.zip&amp;quot;&amp;gt;Download Image&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p style=&amp;quot;text-align: right;&amp;quot;&amp;gt;&amp;lt;em&amp;gt;Sưu tầm&amp;lt;/em&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;</Body><CommentEnabled>True</CommentEnabled><ViewCount>0</ViewCount><ReleaseDate>3/8/2010 8:17:23 PM</ReleaseDate><TotalComment>0</TotalComment><IsMedia>False</IsMedia><IsPicture>False</IsPicture><IsVote>True</IsVote><ArticlePassword /><PostVisible>0</PostVisible><ArticlePath>/2010/3/8/Dong-ho-Javascript-337</ArticlePath><Approved>True</Approved><ImagePath /><CategoryId>30</CategoryId><ArrayCatID>30|25</ArrayCatID></Article></Articles>